package com.example.suuu.project.system.controller;

import com.example.suuu.project.system.entity.SuDepartment;
import com.example.suuu.tools.log.LogPrint;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.example.suuu.project.system.service.impl.SuDepartmentServiceImpl;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.CrossOrigin;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import com.example.suuu.model.result.ResultVo;
import com.example.suuu.project.system.query.SuDepartmentQuery;

import javax.annotation.Resource;

/**
 * @desc 部门 API接口
 * @author sun
 * @date 2023-06-28
 */
@CrossOrigin
@RestController
@RequestMapping("/suDepartment")
@Api(value = "/suDepartment", tags = {"部门 API接口"})
@ApiSupport(author = "sun")
public class SuDepartmentController{

    @Resource
    public SuDepartmentServiceImpl suDepartmentService;


    @PostMapping("/add")
    @LogPrint("部门新增")
    @ApiOperation(value = "部门新增",notes = "部门新增")
    @ApiOperationSupport(ignoreParameters = {"id"})
    public ResultVo add(@Validated @RequestBody SuDepartment u) {
        return ResultVo.ResultVoSuccess(suDepartmentService.add(u));
    }
    @PutMapping("/update")
    @LogPrint("部门修改")
    @ApiOperation(value = "部门修改",notes = "部门修改")
    @ApiOperationSupport(ignoreParameters = {})
    public ResultVo update(@Validated @RequestBody SuDepartment u) {
        return ResultVo.ResultVoSuccess(suDepartmentService.update(u));
    }
    @DeleteMapping("/del/{id}")
    @LogPrint("部门删除")
    @ApiOperation(value = "部门删除",notes = "部门删除")
    public ResultVo del(@Validated @PathVariable(value="id") Integer id) {
        return ResultVo.ResultVoSuccess(suDepartmentService.del(id));
    }
    @GetMapping("/getlist")
    @LogPrint("部门查询")
    @ApiOperation(value = "部门查询",notes = "部门查询")
    @ApiOperationSupport(ignoreParameters = {})
    public ResultVo get(SuDepartmentQuery query) {
        return ResultVo.ResultVoSuccess(suDepartmentService.pagVo(query));
    }
    @GetMapping("/getById/{id}")
    @LogPrint("部门id查询")
    @ApiOperation(value = "部门id查询",notes = "部门id查询")
    @ApiOperationSupport(ignoreParameters = {})
    public ResultVo getById(@Validated @PathVariable(value="id") Integer id) {
        return ResultVo.ResultVoSuccess(suDepartmentService.getById(id));
    }
}